package com.example.shop_2304.xq

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.blankj.utilcode.util.ToastUtils
import com.example.base.mvvm.BaseFragment
import com.example.shop_2304.R
import com.example.shop_2304.databinding.FragmentXqBinding
import com.example.shop_2304.utils.GlideUtils

class XqFragment : BaseFragment<FragmentXqBinding,XqViewModel>() {
    override fun initView() {
        //获取gid
        val xqActivity = activity as XqActivity
        val gid = xqActivity.gid
        viewModel.xq(gid,"normal")
    }

    override fun initData() {
        viewModel.xqSuccess.observe(this){
            if(it.code==200){
                binding.tvPrice.text = "￥${it.data.productInfo.price}"
                binding.tvStorename.text = it.data.productInfo.storeName
                binding.tvOtprice.text = "原价:￥${it.data.productInfo.otPrice}"
                binding.tvSale.text = "销量:${it.data.productInfo.sales+it.data.productInfo.ficti}件"
                binding.tvStock.text = "库存:${it.data.productInfo.stock}件"
                GlideUtils.loadImage(requireActivity(),it.data.productInfo.image,binding.ivImage)
                //规格
                binding.tvSuk.text = "规格:${it.data.productValue.keys.toList()[0]}"
                //it.data.productValue.values.toList()[0].id  默认商品属性值id
            }else{
                ToastUtils.showLong(it.message)
            }
        }
    }

    override fun getLayout(): Int  = R.layout.fragment_xq

    override fun getViewModel(): Class<XqViewModel>  = XqViewModel::class.java

}